package com.example.wxminiprogram.mapper;

import com.example.wxminiprogram.pojo.Goods;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;

@Mapper
public interface GoodsMapper {
    @Select("select * from goods")
    List<Goods> getAll();
    @Select("select * from goods where id = #{id}")
    Goods getById(Integer id);

    @Select("select image from goods_swiper_images where goods_id = #{id}")
    List<String> getSwiperImageById(Integer id);
    @Delete("delete from goods_swiper_images where goods_id = #{goods_id}")
    void deleteSwiperImageByGoods_id(Integer goods_id);
    @Insert("insert into goods_swiper_images (goods_id,image) values (#{goods_id},#{image})")
    void insertSwiperImageByGoods_idAndImage(Integer goods_id,String image);
    @Select("select * from goods where shop_id= #{shop_id}")
    List<Goods> getByShopId(Integer shop_id);
    @Update("update goods set goods_name = #{goods_name},goods_price=#{goods_price},goods_class = #{goods_class} where id = #{id}")
    void updateByGoods(Goods goods);
    @SelectKey(statement="select LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    @Insert("insert into goods(id,goods_name,goods_price,goods_class,goods_introduce,goods_icon,shop_id) values (#{id},#{goods_name},#{goods_price},#{goods_class},#{goods_introduce},#{goods_icon},#{shop_id})")
    Integer insert(Goods goods);

    List<Goods> search(Integer cid,String query,Integer pagenum,Integer pagesize);
    @Delete("delete from goods where id = #{id}")
    void deleteGoodsById(Integer id);
    @Update("update goods set goods_icon = #{goods_icon} where id = #{id}")
    void updateIconById(String goods_icon,Integer id);
    @Update("update goods set goods_introduce = #{goods_introduce} where id = #{id}")
    void updateIntroduceById(String goods_introduce,Integer id);
    @Update("update goods set goods_quality = #{goods_quality} where id = #{id}")
    void updateQualityById(Goods goods);
    @Insert("insert into goods_swiper_images(image,goods_id)values (#{image},#{goods_id})")
    void insertSwiperByGoodsId(String image,Integer goods_id);
    @Select("select count(*) from goods_swiper_images where goods_id = #{goods_id}")
    Integer getSwiperNumByGoodsId(Integer goods_id);
    @Delete("delete from goods_swiper_images where id = #{id}")
    void deleteSwiperById(Integer id);
    @Select("select MIN(id) from goods_swiper_images where goods_id = #{goods_id}")
    Integer getMinIdByGoodsId(Integer goods_id);
    @Select("select MAX(id) from goods_swiper_images")
    Integer getMaxId();
    @Select("select image from goods_swiper_images where id = #{id}")
    String getImageById(Integer id);
}
